package joc.internal;

import joc.internal.util.ObjectMapper;

public class Cache {
	private final static ThreadLocal<ObjectMapper<String, ConditionWrapper>> conditionCache = new ThreadLocal<ObjectMapper<String, ConditionWrapper>>() {
		@Override
		protected ObjectMapper<String, ConditionWrapper> initialValue() {
			return new ObjectMapper<String, ConditionWrapper>();
		}
	};

	public static void saveCondition(Object obj, String key, Object condition) {
		conditionCache.get().put(obj, key, new ConditionWrapper(condition));
	}

	public static boolean containsCondition(Object obj, String key) {
		return conditionCache.get().contains(obj, key);
	}

	public static Object getCondition(Object obj, String key) {
		return conditionCache.get().get(obj, key).getCondition();
	}

	public static void activateCondition(Object obj, String key) {
		conditionCache.get().get(obj, key).setActive(true);
	}

	public static void deactivateCondition(Object obj, String key) {
		conditionCache.get().get(obj, key).setActive(false);
	}

	public static boolean isConditionActive(Object obj, String key) {
		return conditionCache.get().get(obj, key).isActive();
	}
}
